package edu.cmu.cs.stage3.alice.core.behavior;

import edu.cmu.cs.stage3.alice.core.RenderTarget;
import edu.cmu.cs.stage3.alice.core.World;
import edu.cmu.cs.stage3.alice.core.property.BooleanProperty;
import edu.cmu.cs.stage3.alice.core.property.NumberProperty;
import edu.cmu.cs.stage3.alice.core.property.TransformableProperty;

public class MouseLookingBehavior extends InternalResponseBehavior implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener {



	private RenderTarget renderTarget;

	private int lastX;
	private int lastY;

	public NumberProperty turningRate = new NumberProperty( this, "turningRate", new Double(.001) );
	public TransformableProperty subject = new TransformableProperty( this, "subject", null );
	public BooleanProperty onlyAffectsYaw = new BooleanProperty(this, "onlyAffectsYaw", Boolean.TRUE );

	protected void disable() {
		renderTarget.removeMouseListener( this );
		renderTarget.removeMouseMotionListener( this );
	}

	protected void enable() {
		renderTarget.addMouseListener( this );
		renderTarget.addMouseMotionListener( this );
	}


	//Rem @Override
	public void started( World world, double time ) {
		super.started( world, time );

		if( isEnabled.booleanValue() ) {
			enable();

		}
	}

	//Rem @Override
	public void stopped( World world, double time ) {
		super.stopped( world, time );
		if( isEnabled.booleanValue() ) {
			disable();
		}
	}

	//Rem @Override
	public void internalSchedule( double time, double dt ) {
	}

	// Implements MouseListener
	public void mouseClicked(java.awt.event.MouseEvent e) {}
	public void mouseEntered(java.awt.event.MouseEvent e) {
		lastX = e.getX();
		lastY = e.getY();
	}

	public void mouseExited(java.awt.event.MouseEvent e) {}
	public void mousePressed(java.awt.event.MouseEvent e) {
		lastX = e.getX();
		lastY = e.getY();
	}
	public void mouseReleased(java.awt.event.MouseEvent e) {
	}

	// Implements MouseMotionListener
	public void mouseDragged(java.awt.event.MouseEvent e) {
		if (lastX==-1) {
		}
		if (lastY==-1) {
		}
		lastX=e.getX();
		lastY=e.getY();
	}

	public void mouseMoved(java.awt.event.MouseEvent e) {
		if (lastX==-1) {
		}
		if (lastY==-1) {
		}
		lastX=e.getX();
		lastY=e.getY();
	}

}